﻿using System;
using System.IO;
using Terraria.Localization;

namespace Terraria.DataStructures
{
	// Token: 0x02000482 RID: 1154
	public class PlayerDeathReason
	{
		// Token: 0x060026C0 RID: 9920 RVA: 0x0001AF4D File Offset: 0x0001914D
		public static PlayerDeathReason LegacyEmpty()
		{
			return new PlayerDeathReason
			{
				SourceOtherIndex = 254
			};
		}

		// Token: 0x060026C1 RID: 9921 RVA: 0x0001AF5F File Offset: 0x0001915F
		public static PlayerDeathReason LegacyDefault()
		{
			return new PlayerDeathReason
			{
				SourceOtherIndex = 255
			};
		}

		// Token: 0x060026C2 RID: 9922 RVA: 0x0001AF71 File Offset: 0x00019171
		public static PlayerDeathReason ByNPC(int index)
		{
			return new PlayerDeathReason
			{
				SourceNPCIndex = index
			};
		}

		// Token: 0x060026C3 RID: 9923 RVA: 0x0001AF7F File Offset: 0x0001917F
		public static PlayerDeathReason ByCustomReason(string reasonInEnglish)
		{
			return new PlayerDeathReason
			{
				SourceCustomReason = reasonInEnglish
			};
		}

		// Token: 0x060026C4 RID: 9924 RVA: 0x00492CDC File Offset: 0x00490EDC
		public static PlayerDeathReason ByPlayer(int index)
		{
			return new PlayerDeathReason
			{
				SourcePlayerIndex = index,
				SourceItemType = Main.player[index].inventory[Main.player[index].selectedItem].type,
				SourceItemPrefix = (int)Main.player[index].inventory[Main.player[index].selectedItem].prefix
			};
		}

		// Token: 0x060026C5 RID: 9925 RVA: 0x0001AF8D File Offset: 0x0001918D
		public static PlayerDeathReason ByOther(int type)
		{
			return new PlayerDeathReason
			{
				SourceOtherIndex = type
			};
		}

		// Token: 0x060026C6 RID: 9926 RVA: 0x00492D40 File Offset: 0x00490F40
		public static PlayerDeathReason ByProjectile(int playerIndex, int projectileIndex)
		{
			PlayerDeathReason playerDeathReason = new PlayerDeathReason
			{
				SourcePlayerIndex = playerIndex,
				SourceProjectileIndex = projectileIndex,
				SourceProjectileType = Main.projectile[projectileIndex].type
			};
			if (playerIndex >= 0 && playerIndex <= 255)
			{
				playerDeathReason.SourceItemType = Main.player[playerIndex].inventory[Main.player[playerIndex].selectedItem].type;
				playerDeathReason.SourceItemPrefix = (int)Main.player[playerIndex].inventory[Main.player[playerIndex].selectedItem].prefix;
			}
			return playerDeathReason;
		}

		// Token: 0x060026C7 RID: 9927 RVA: 0x0001AF9B File Offset: 0x0001919B
		public NetworkText GetDeathText(string deadPlayerName)
		{
			if (this.SourceCustomReason != null)
			{
				return NetworkText.FromLiteral(this.SourceCustomReason);
			}
			return Lang.CreateDeathMessage(deadPlayerName, this.SourcePlayerIndex, this.SourceNPCIndex, this.SourceProjectileIndex, this.SourceOtherIndex, this.SourceProjectileType, this.SourceItemType);
		}

		// Token: 0x060026C8 RID: 9928 RVA: 0x00492DC8 File Offset: 0x00490FC8
		public void WriteSelfTo(BinaryWriter writer)
		{
			BitsByte bb = 0;
			bb[0] = (this.SourcePlayerIndex != -1);
			bb[1] = (this.SourceNPCIndex != -1);
			bb[2] = (this.SourceProjectileIndex != -1);
			bb[3] = (this.SourceOtherIndex != -1);
			bb[4] = (this.SourceProjectileType != 0);
			bb[5] = (this.SourceItemType != 0);
			bb[6] = (this.SourceItemPrefix != 0);
			bb[7] = (this.SourceCustomReason != null);
			writer.Write(bb);
			if (bb[0])
			{
				writer.Write((short)this.SourcePlayerIndex);
			}
			if (bb[1])
			{
				writer.Write((short)this.SourceNPCIndex);
			}
			if (bb[2])
			{
				writer.Write((short)this.SourceProjectileIndex);
			}
			if (bb[3])
			{
				writer.Write((byte)this.SourceOtherIndex);
			}
			if (bb[4])
			{
				writer.Write((short)this.SourceProjectileType);
			}
			if (bb[5])
			{
				writer.Write((short)this.SourceItemType);
			}
			if (bb[6])
			{
				writer.Write((byte)this.SourceItemPrefix);
			}
			if (bb[7])
			{
				writer.Write(this.SourceCustomReason);
			}
		}

		// Token: 0x060026C9 RID: 9929 RVA: 0x00492F34 File Offset: 0x00491134
		public static PlayerDeathReason FromReader(BinaryReader reader)
		{
			PlayerDeathReason playerDeathReason = new PlayerDeathReason();
			BitsByte bitsByte = reader.ReadByte();
			if (bitsByte[0])
			{
				playerDeathReason.SourcePlayerIndex = (int)reader.ReadInt16();
			}
			if (bitsByte[1])
			{
				playerDeathReason.SourceNPCIndex = (int)reader.ReadInt16();
			}
			if (bitsByte[2])
			{
				playerDeathReason.SourceProjectileIndex = (int)reader.ReadInt16();
			}
			if (bitsByte[3])
			{
				playerDeathReason.SourceOtherIndex = (int)reader.ReadByte();
			}
			if (bitsByte[4])
			{
				playerDeathReason.SourceProjectileType = (int)reader.ReadInt16();
			}
			if (bitsByte[5])
			{
				playerDeathReason.SourceItemType = (int)reader.ReadInt16();
			}
			if (bitsByte[6])
			{
				playerDeathReason.SourceItemPrefix = (int)reader.ReadByte();
			}
			if (bitsByte[7])
			{
				playerDeathReason.SourceCustomReason = reader.ReadString();
			}
			return playerDeathReason;
		}

		// Token: 0x0400437B RID: 17275
		public int SourcePlayerIndex = -1;

		// Token: 0x0400437C RID: 17276
		public int SourceNPCIndex = -1;

		// Token: 0x0400437D RID: 17277
		public int SourceProjectileIndex = -1;

		// Token: 0x0400437E RID: 17278
		public int SourceOtherIndex = -1;

		// Token: 0x0400437F RID: 17279
		public int SourceProjectileType;

		// Token: 0x04004380 RID: 17280
		public int SourceItemType;

		// Token: 0x04004381 RID: 17281
		public int SourceItemPrefix;

		// Token: 0x04004382 RID: 17282
		public string SourceCustomReason;
	}
}
